package net.form.processing;

import java.awt.Color;

public class ClusterAspectRatio extends Cluster {

	private int count;
	private double acumulador;

	public ClusterAspectRatio(int id, int heft, double value) {
		super(id, heft);
		addValue(value);
	}

	@Override
	public void clear() {
		count = 0;
		acumulador = 0;
	}

	@Override
	public double getValue() {
		if (count != 0) {
			return acumulador / count;
		}
		return 0;
	}

	@Override
	public void addValue(double value) {
		count++;
		this.acumulador += value;
	}

	@Override
	public void removeValue(double value) {
		count--;
		this.acumulador -= value;
	}

	@Override
	public double distance(double value) {
		return Math.abs(getValue() - value);
	}

	@Override
	public int getColor() {
		return getColor(id);
	}

	public int getColor(int id) {
		int color = 0;
		switch (id + 1) {
		case 1:
			color = Color.red.getRGB();
			break;
		case 2:
			color = Color.blue.getRGB();
			break;
		case 3:
			color = Color.green.getRGB();
			break;
		case 4:
			color = Color.yellow.getRGB();
			break;
		case 5:
			color = Color.pink.getRGB();
			break;
		case 6:
			color = Color.cyan.getRGB();
			break;
		case 7:
			color = Color.magenta.getRGB();
			break;
		case 8:
			color = Color.black.getRGB();
			break;
		case 9:
			color = Color.gray.getRGB();
			break;
		case 10:
			color = Color.orange.getRGB();
			break;
		case 11:
			color = Color.white.getRGB();
			break;
		default:
			color = Math.round((id + id + id + id + 10) * (int) getValue());
			break;
		}
		return color;
	}

	@Override
	public String getType() {
		return "Aspect Ratio";
	}

	@Override
	public Object clone() {
		ClusterAspectRatio clase = new ClusterAspectRatio(this.id, this.heft,
				this.getValue());
		return clase;
	}

}
